// pages/find/fitness/detail/buy/buy.js
import { HTTP } from '../../../../../utils/http.js'
let ajax = new HTTP()
var app = getApp()

Page({
    data: {
        buyList: {},
        nameValue: "",
        phoneValue: ""
    },
    onLoad (options) {
        wx.showLoading({
            title: '加载中',
        })
        this._getDetailList(app.globalData.memberid, options.id)
    },
    // 购买课程
    sureBuy () {
        let name = this.data.nameValue
        let phone = this.data.phoneValue
        console.log(name, phone)
        if (name === "" || phone === "") {
            wx.showToast({
                title: '信息不能为空',
                icon: 'none'
            })
            return
        }
    },
    // 姓名失焦
    inputNameBlur(event) {
        this.setData({
            nameValue: event.detail.value
        })
    },
    // 手机号失焦
    inputPhoneBlur(event) {
        let phone = event.detail.value
        if (!this._isPhoneNumber(phone)) {
            wx.showToast({
                title: '手机号码有误',
                icon: 'none'
            })
            this.setData({
                phoneValue: ""
            })
            return
        } else {
            this.setData({
                phoneValue: phone
            })
        }
    },
    // 转发 
    onShareAppMessage: function () {

    },
    // 手机号判断
    _isPhoneNumber(phone) {
        if (!(/^1[34578]\d{9}$/.test(phone)) || phone == "") {
            return false;
        } else {
            return true;
        }
    },
    // 请求信息
    _getDetailList(memberid, id) {
        ajax.request({
            url: "trainlist/read",
            data: {
                memberid: memberid,
                id: id
            },
            success: (res) => {
                res = res.data
                this.setData({
                    buyList: res
                })
                wx.hideLoading()
            }
        })
    }
})